export function setToFormData(data){
  const keys = Object.keys(data)
  if (keys.length > 0) {
    const result = new FormData()
    keys.forEach(key => {
      result.append(key, data[key])
    })
    return result
  }
  return false
}

export function setInvitationUrl(router) {
  const origin = location.origin
  const pathName = location.pathname
  return  encodeURIComponent(origin + pathName + router)
}

export function setShareUrl(router) {
  const origin = location.origin
  const pathName = location.pathname
  return  origin + pathName + router
}

function fnGetQueryString(key) { //正则获取url后面的参数值，如?env=dev&exp=123中可以通过fnGetQueryString('exp')=>得到123
  var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)")
  var result = window.location.search.substr(1).match(reg)
  return result ? decodeURIComponent(result[2]) : false
}
function refreshUrl() {//强制刷新到不带二次分享参数页面
  var url = "";
  const origin = location.origin
  const pathname = location.pathname
  const hash = location.hash
  return origin + pathname + hash // https://wx.shendu.cn + /insurance/renbaoSpreac + '#/invitation?type=xxxx'

};

export function checkIfSecondWechatShareBug() {
  if (fnGetQueryString('from')||fnGetQueryString('isappinstalled')) {
    //return false
    location.href = refreshUrl();
  }
  return true
}
